<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>滚动事件</title>
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            height: 100%;
            background: #dadada;
            -webkit-user-select:none;
            -moz-user-select:none;
            -o-user-select:none;
            user-select:none;
        }

        header {
            height: 44px;
            line-height: 44px;
            text-align: center;
            background: #da020c;
            color: #fff;
        }

        h1 {
            margin: 0;
            padding: 0;
            font-size: 18px;
            font-weight: normal;
        }

        a {
            height: 34px;
            line-height: 34px;
            position: absolute;
            top: 5px;
            left: 10px;
        }

        #wrapper {
            position: absolute;
            top: 44px;
            bottom: 0;
            width: 100%;
        }

        #scroller {
            margin: 0;
            padding: 0;
            background: #fff;
        }

        #scroller li {
            height: 60px;
            line-height: 60px;
            border-bottom: 1px solid #ddd;
            text-indent: 1em;
            background: #fff;
        }

        #scroller li:nth-last-child(1) {
            border-bottom: none;
        }

        #info {
            position: absolute;
            top: 60px;
            right: 20px;
            background: rgba(0, 0, 0, .2);
            line-height: 30px;
            padding: 0 10px;
            width: 140px;
            font-size: 14px;
        }

        #info>div {
            height: 30px;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <header>
        <h1>滚动事件</h1>
        <a onclick="javascript:history.back()">&lt;返回</a>
    </header>
    <div id="wrapper">
        <div id="scroller">
        </div>
    </div>
    <div id="info">
        <div>事件：<span id="evt">null</span></div>
        <div>位置：<span id="pos">(0, 0)</span></div>
    </div>

    <script src="../vendor/fastclick.js"></script>
    <script src="../src/jroll.js"></script>
    <script>
        var jroll = new JRoll("#wrapper", {
            id: "demo3"
        });
        var evt = document.getElementById("evt");
        var pos = document.getElementById("pos");

        FastClick.attach(document.body);

        function createLi(n) {
            var html = "";
            for (var i = 0; i < n; i++) {
                html += "<li>" + (i + 1) + "</li>";
            }
            scroller.innerHTML = html;
            jroll.scrollTo(0, 0).refresh();
        }

        createLi(40);

        jroll.on("scrollStart", function() {
            evt.innerText = "scrollStart";
            pos.innerText = "(0, " + this.y.toFixed(2) + ")";
        });

        jroll.on("scroll", function() {
            evt.innerText = "scroll";
            pos.innerText = "(0, " + this.y.toFixed(2) + ")";
        });

        jroll.on("scrollEnd", function() {
            evt.innerText = "scrollEnd";
            pos.innerText = "(0, " + this.y.toFixed(2) + ")";
        });

        jroll.on("touchEnd", function() {
            evt.innerText = "touchEnd";
        });

        //旋转屏幕会执行该事件
        jroll.on("refresh", function() {
            evt.innerText = "refresh";
        });
    </script>
</body>

</html>